//定义基础路径
const baserUrl  = 'https://gmall-prod.atguigu.cn'
import {getToken} from "/src/tool/token"
interface parameterMod  {
    url:string,
    method:string,
    data?:any,
}

export default (parameter:parameterMod) => {
    return new Promise((req,res)=>{
        //开启login状态
        wx.showLoading({
            title:'加载中',
            mask:true
        })
        let header = {
            'content-type': 'application/json',
        }
        let token = getToken('userInfoToken')
        header.token = token;
        uni.request({
            url:`${baserUrl}${parameter.url}`,
            method:parameter.method?parameter.method : 'GET',
            data:parameter,
            timeout:5000,
            header,
            success(res){
                return  req(res.data)
            },
            fail(err){
                res(err)
            },
            complete(){
                wx.hideLoading()
            }
        })
    })
}
